﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traceability_Management.Infrastructure.Interfaces;

namespace Traceability_Management.Infrastructure.Implements
{
    public class BaseReponsitory<T> : IBaseReponsitory<T> where T : class
    {
        DbdataContext context;
        DbSet<T> Dbset;
        public BaseReponsitory(DbdataContext context)
        {
            this.context = context;
            this.Dbset = context.Set<T>();
        }
        //异步添加
        public async Task<int> AddAsync(T entity)
        {
        await context.Set<T>().AddAsync(entity);
    return await context.SaveChangesAsync();
        }
        //异步删除
        public async Task<int> DeleteAsync(T entity)
        {
            return 1;
        }
        //异步更新
        public async Task<int> UpdateAsync(T entity)
        {
             context.Set<T>().Update(entity);
            return await context.SaveChangesAsync();
        }
        //异步查询
        public IQueryable<T> GetQuery()
        {
            return context.Set<T>().AsQueryable();
        }
    }
}
